<template>
	<view class="mine">
		<bgc-mine :bgcMineData= "bgcMineData" @commitBgc="commitBgc"></bgc-mine>
		<list-mine :mineData = "mineData" :userImg="userImg"></list-mine>
	</view>
</template>

<script>
	import {getMine,postBgIMg,postAvatar} from "../../network/mine.js"
	
	import BgcMine from "./childMine/BgcMine.vue"
	import ListMine from "./childMine/ListMine.vue"
	
	export default {
		onPullDownRefresh() {
			this._getMine()
			uni.stopPullDownRefresh()
		},
		components:{
			BgcMine,
			ListMine
		},
		data() {
			return {
				mineData:{},
				userImg:"",
				bgcMineData:null
			}
		},
		onLoad() {
			this._getMine()
		},
		activated() {
			this._getMine()
		},
		methods: {
			_getMine(){
				getMine().then(res=>{
					if(res.data.code !== "A001"){
						uni.navigateTo({
							url:"../../components/content/LostLogin"
						})
					}
					this.mineData = res.data.result[0]
					this.bgcMineData = res.data.result[0].userBg
					this.userImg = res.data.result[0].userImg
					getApp().globalData.nickName = res.data.result[0].nickName
				})
			},
			commitBgc(e){
				postBgIMg(e).then(res=>{
					if(res.data.code == "I001"){
						uni.showToast({
						    title: res.data.msg,
						    duration: 2000,
							icon:'none'
						})
						setTimeout(()=>{
							uni.switchTab({
								url:"../mine/Mine"
							})
						},1000)
					}else{
						uni.showToast({
						    title: res.data.msg,
						    duration: 2000,
							icon:'none'
						})
					}
				}).catch(Error=>{
					uni.showToast({
					    title: "图片格式不正确",
					    duration: 2000,
						icon:'none'
					})
				})
			},
		}
	}
</script>

<style scoped>
</style>
